<?php
if( empty( $_SESSION ) )
{
	session_start();
}
header("Content-Type: text/html; charset=utf-8",true);

include("fckeditor.php");
include_once("../../includes/restrito.php");
include_once("../models/cls.colaborador.php");

$oColaborador = new colaborador();

switch( isset( $_GET["acao"] ) )
{
	case "editar" :
		$oColaborador->select( $_GET["id"] );
		break;
		
	case "excluir" :
		$oColaborador->delete( $_GET["id_delete"], "../views/frm.colaborador.php" );
		break;
		
	case "ativar" :
		$oColaborador->situacao( $_GET["id"] , $_GET["acao"] );
		break;
		
	case "desativar";
		$oColaborador->situacao( $_GET["id"] , $_GET["acao"] );
		break;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>IDIOMA</title>
<link rel="stylesheet" type="text/css" href="../../includes/sistema.css"/>
<script>
function _excluir(id)
{
	if(confirm("Por favor, confirme há remoção!"))
	{
		window.location.href="frm.colaborador.php?id_delete=" + id + "&acao=excluir";
	}	
}

function _salvar(){
	if(document.frm.nome.value=="")
	{
		alert("Por favor, informe o nome do colaborador!");
		document.frm.nome.focus();
		return;
	}
	if(document.frm.email.value=="")
	{
		alert("Por favor, informe o e-mail do colaborador!");
		document.frm.email.focus();
		return;
	}

	if(document.frm.biografia.value=="")
	{
		alert("Por favor, informe a biografia ou parte da biografia do colaborador!");
		document.frm.biografia.focus();
		return;
	}

	document.frm.submit();
}
</script>
</head>
<body>
<div id="content">
  <h2>Colaborador</h2>
  <hr size="1" noshade="noshade">
    <form name="frm" method="post" action="../controllers/ctl.colaborador.php">
      <table width="100%" border="0" align="center">
        <tr>
          <td width="45%">Nome:
          <input name="nome" type="text" class="form100pc" value="<?php echo $oColaborador->nome; ?>" /></td>
          <td width="45%">Email
          <input name="email" type="text" class="form100pc" value="<?php echo $oColaborador->email; ?>" /></td>
          <td width="8%">Situação: <br />
            <select name="situacao" class="form100px">
              <option value="1" <?php if( $oColaborador->situacao == 1 ){ echo " selected"; } ?>>Ativar</option>
              <option value="0" <?php if( $oColaborador->situacao == 0 ){ echo " selected"; } ?>>Desativar</option>
          </select></td>
        </tr>
        <tr>
          <td colspan="3">
            
            Biografia:<br />
            <?php
        $sBasePath = $_SERVER['PHP_SELF'] ;
        $sBasePath = substr( $sBasePath, 0, strpos( $sBasePath, "editor" ) ) ;
        
        $oFCKeditor = new FCKeditor('biografia',200);
        $oFCKeditor->BasePath = $sBasePath;
		if( ! empty( $oColaborador->biografia ) )
		{
        	$oFCKeditor->Value = $oColaborador->biografia;
		}
		else
		{
			$oFCKeditor->Value = "&nbsp;";
		}
        $oFCKeditor->Create();
        ?>
        
        </td>
        </tr>
        <tr>
          <td colspan="3"><input name="btnSubmit" type="button" class="formButton" value="SALVAR" onclick="_salvar()" />
          <input name="id" type="hidden" value="<?php echo $oColaborador->id; ?>" /></td>
        </tr>
      </table>
<hr size="1" noshade="noshade">
    </form>    
<?php
$cor=true;
$aOrdem = array( "nome" , "ASC" );

$aColaborador = $oColaborador->select( "" , $aOrdem );

if( ! empty( $aColaborador ) )
{
	echo '<table width=100%>';
	echo '<th align="left">NOME</th>';
	echo '<th align="left">E-MAIL</th>';
	echo '<th align="center">SITUAÇÃO</th>';
	echo '<th align="center">EDITAR</th>';
	echo '<th align="center">EXCLUIR</th>';

	foreach($aColaborador as $sItem) // VARRE A LISTA E IMPRIME OS ÍNDICES DA COLEÇÃO
	{
		// ALTERNA AS CORES DA LINHA DA TABELA A CADA REGISTRO IMPRESSO
		if($cor)
		{
			$tdcor = "#F4F4F4"; //CINZA CLARO
			$cor=false;
		}
		else{
			$tdcor = "#FFFFFF"; //BRANCO
			$cor = true;
		}
		
		echo '<tr bgcolor="'. $tdcor .'">';
	
		echo '<td>' . $sItem['nome'] . '</td>';
		echo '<td>' . $sItem['email'] . '</td>';
		
		if($sItem["situacao"] == 0)
		{
			echo '<td width="10%" align="center"><a href="frm.colaborador.php?id=' . $sItem["id"] . '&acao=ativar"><img src="../imagens/ativar.out.png" border="0"></a></td>';
		}
		else
		{
			echo '<td width="10%" align="center"><a href="frm.colaborador.php?id=' . $sItem["id"] . '&acao=desativar"><img src="../imagens/ativar.png" border="0"></a></td>';
		}
		echo '<td width="10%" align="center"><a href="frm.colaborador.php?id=' . $sItem["id"] . '&acao=editar"><img src="../imagens/editar.png" border="0"></a></td>';
		echo '<td width="10%" align="center"><a href="javascript:_excluir(' . $sItem["id"] . ');"><img src="../imagens/excluir.png" border="0"></a></td>';
		echo '</tr>';
	}
	echo '</table>';

}
else
{
	echo "Não há colaboradores cadastrados!";	
}
?>
    
</div>
</body>
</html>
